/***************************************************************************
 创建者：          hualei
 开始时间：      2018.09.10
 copyright:(C)    深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************/
#include "movefreemovetypeview.h"
#include "ui_movefreemovetypeview.h"
#include "../../programView/programview.h"

MoveFreeMoveTypeView::MoveFreeMoveTypeView(int styleId,QDialog *parent) :
    QDialog(parent),
    ui(new Ui::MoveFreeMoveTypeView)
{
    ui->setupUi(this);
    initialDisplayStyle(styleId);
    cntValue=100;
    ui->CNT_Value_Edit->setText(QString::number(cntValue));
}

void MoveFreeMoveTypeView::initialDisplayStyle(int styleId)
{
    switch (styleId) {
    case 1:
        ui->ConfirmBtn->setGeometry(270,345,60,40);
        ui->cancel_Btn->setGeometry(360,345,70,40);
        break;
    default:
        break;
    }
}

void MoveFreeMoveTypeView::getInput()
{
    if(ui->CNT_CBox->currentIndex() == 1)
    {
        cntValue = ui->CNT_Value_Edit->text().toInt();
    }
    else
    {
        cntValue = 0;
    }

    if(0==ui->MoveTrajectory_CBox->currentIndex())
    {
        moveFreeMoveTrajectoryType = E_MOVE_FREE_MOVE_TRAJECTORY_AUTO;
    }
    else if(1==ui->MoveTrajectory_CBox->currentIndex())
    {
        moveFreeMoveTrajectoryType = E_MOVE_FREE_MOVE_TRAJECTORY_LINE;
    }
    else if(2==ui->MoveTrajectory_CBox->currentIndex())
    {
        moveFreeMoveTrajectoryType = E_MOVE_FREE_MOVE_TRAJECTORY_SPLINE;
    }
    else if(3==ui->MoveTrajectory_CBox->currentIndex())
    {
        moveFreeMoveTrajectoryType = E_MOVE_FREE_MOVE_TRAJECTORY_ROTATE;
    }
    else
    {
        qDebug()<<"error, unknow moveFreeMoveTrajectoryType";
    }
    allowAccuracy = ui->StopPrecision_Edit->text().toDouble();
    //DETECT BARRIER　探测障碍
    detectBarrierState = ui->DetectBarrier_CBox->currentIndex();
    barrierRunMode = ui->DetectBarrier_CBox_detectModeIndex->currentIndex();

//    qDebug() << "cntValue :" << cntValue;
//    qDebug() << "moveFreeMoveTrajectoryType :" << moveFreeMoveTrajectoryType;
//    qDebug() << "allowAccuracy :" << allowAccuracy;
//    qDebug() << "validLaserRange_moving :" << validLaserRange_moving;
//    qDebug() << "validLaserRange_stopping :" << validLaserRange_stopping;
}

void MoveFreeMoveTypeView::updateView()
{
    if(cntValue == 0)
    {
        ui->CNT_Label->hide();
        ui->CNT_Value_Edit->hide();
        ui->CNT_CBox->setCurrentIndex(0);
    }
    else
    {
        ui->CNT_CBox->setCurrentIndex(1);
        ui->CNT_Label->show();
        ui->CNT_Value_Edit->show();
        ui->CNT_Value_Edit->setText(QString::number(cntValue));
    }

    if(moveFreeMoveTrajectoryType == E_MOVE_FREE_MOVE_TRAJECTORY_AUTO)
    {
        ui->MoveTrajectory_CBox->setCurrentIndex(0);
    }
    else if(moveFreeMoveTrajectoryType == E_MOVE_FREE_MOVE_TRAJECTORY_LINE)
    {
        ui->MoveTrajectory_CBox->setCurrentIndex(1);
    }
    else if(moveFreeMoveTrajectoryType == E_MOVE_FREE_MOVE_TRAJECTORY_SPLINE)
    {
        ui->MoveTrajectory_CBox->setCurrentIndex(2);
    }
    else if(moveFreeMoveTrajectoryType == E_MOVE_FREE_MOVE_TRAJECTORY_ROTATE)
    {
        ui->MoveTrajectory_CBox->setCurrentIndex(3);
    }
    else
    {
        qDebug()<<"error,unknow moveFreeMoveTrajectoryType"<<moveFreeMoveTrajectoryType;
    }

    ui->StopPrecision_Edit->setText(QString::number(allowAccuracy));

    //DETECT BARRIER　探测障碍

    if( (detectBarrierState <= E_MOVE_FREE_DETECT_BARRIER_YES) && (detectBarrierState >= E_MOVE_FREE_DETECT_BARRIER_NO))
    {
        ui->DetectBarrier_CBox->setCurrentIndex(detectBarrierState);
    }
    ui->DetectBarrier_CBox_detectModeIndex->setCurrentIndex(barrierRunMode);


//    ui->MovingMatchRange_Edit->setText(QString::number(validLaserRange_moving));
//    ui->StopMatchRange_Edit->setText(QString::number(validLaserRange_stopping));

//    qDebug() << "cntValue :" << cntValue;
//    qDebug() << "moveFreeMoveTrajectoryType :" << moveFreeMoveTrajectoryType;
//    qDebug() << "allowAccuracy :" << allowAccuracy;
//    qDebug() << "validLaserRange_moving :" << validLaserRange_moving;
//    qDebug() << "validLaserRange_stopping :" << validLaserRange_stopping;
}

void MoveFreeMoveTypeView::changeLanguage()
{
    ui->retranslateUi(this);
}

void MoveFreeMoveTypeView::on_ConfirmBtn_clicked()
{
    getInput();
    this->close();
    programView->moveFreeInstructionView->show();
}

void MoveFreeMoveTypeView::on_cancel_Btn_clicked()
{
    this->close();
    programView->moveFreeInstructionView->show();
}

void MoveFreeMoveTypeView::on_CNT_CBox_currentIndexChanged(const QString &arg1)
{
    if(arg1 == "CNT")
    {
        ui->CNT_Label->show();
        ui->CNT_Value_Edit->show();
    }
    else
    {
        ui->CNT_Label->hide();
        ui->CNT_Value_Edit->hide();
    }
}
